import os
import tkinter as tk
from tkinter import messagebox
from tkinter.scrolledtext import ScrolledText

def show_help(right_frame):
    for widget in right_frame.winfo_children():  # 清除 right_frame 中已有的控件
        widget.destroy()

    # 使用 Frame 将帮助内容放在 right_frame 内
    help_text_frame = tk.Frame(right_frame)
    help_text_frame.pack(fill="both", expand=True)

    try:
        # 获取当前 Python 文件的目录
        current_dir = os.path.dirname(os.path.abspath(__file__))
        help_file_path = os.path.join(current_dir, 'help.txt')

        # 读取 help.txt 文件内容
        with open(help_file_path, 'r', encoding='utf-8') as file:
            help_content = file.read()

        # 使用 ScrolledText 显示长文本
        help_text = ScrolledText(help_text_frame, wrap="word", font=("Arial", 12))
        help_text.pack(fill="both", expand=True)

        # 插入文本并设置为只读
        help_text.insert(tk.END, help_content)
        help_text.config(state=tk.DISABLED)

        # 设置最大高度
        help_text_frame.pack_propagate(False)  # 防止 Frame 根据内容自动调整大小

    except FileNotFoundError:
        messagebox.showerror("错误", "help.txt 文件未找到！")
